<style scoped lang="scss">
</style>
<template>
  <div class="app-container">
    <div class="">
      <el-form :inline="true" :model="listQuery">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="">
              <el-input v-model="listQueryFieldValue" placeholder="请输入内容" class="input-with-select" clearable>
                <el-select slot="prepend" v-model="listQueryField" placeholder="请选择" style="width: 120px">
                  <el-option v-for="(item,key) in listQueryFieldMap" :key="key" :value="item.field" :label="item.label">{{ item.label }}</el-option>
                </el-select>
              </el-input>
            </el-form-item>
            <el-form-item>
              <el-button v-waves plain class="filter-item" @click="resetGetList()">重置</el-button>
              <el-button v-waves type="primary" icon="el-icon-search" class="filter-item" @click="getList">搜索</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      fit
      highlight-current-row
      border
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
    >
      <el-table-column align="center" type="index" width="70" label="序号" />
      <el-table-column label="用户名" prop="username" />
      <el-table-column label="姓名" prop="name" />
      <el-table-column label="手机号" prop="phone" />
      <el-table-column label="最后登录IP" prop="ip" />
      <el-table-column label="最后登录时间" prop="login_at" />
      <el-table-column label="创建时间" prop="created_at" />
      <el-table-column label="更新时间" prop="updated_at" />
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.page_size" @pagination="getList" />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination/index.vue' // Secondary package based on el-pagination
import { getLessonUserList } from '@/api/lesson/lesson'
export default {
  components: { Pagination },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: false,
      listQueryFieldMap: [
        { field: 'username', label: '用户名' },
        { field: 'phone', label: '手机号' },
        { field: 'keyword', label: '关键字' }
      ],
      listQueryField: 'username',
      listQueryFieldValue: null,
      listQuery: {
        page: 1,
        page_size: 10,
        username: '',
        phone: '',
        keyword: ''
      },
      formTitle: '新增',
      formVisible: false,
      form: {
        id: 0,
        username: '',
        name: '',
        phone: '',
        avatar: '',
        role_ids: []
      },
      rules: {
        username: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入', trigger: 'blur' }
        ]
      },
      roleList: []
    }
  },
  watch: {
    listQueryField(newField, oldField) {
      this.listQuery[newField] = this.listQueryFieldValue
      this.listQuery[oldField] = null
    },
    listQueryFieldValue(newValue, oldValue) {
      this.listQuery[this.listQueryField] = newValue
    }
  },
  created() {
    this.getList()
  },
  methods: {
    resetGetList() {
      this.listQuery = {
        page: 1,
        page_size: 10,
        keyword: ''
      }
      this.listQueryFieldValue = null
      this.getList()
    },
    getList() {
      this.listLoading = true
      getLessonUserList(this.listQuery).then(res => {
        this.list = res.list
        this.total = res.total
      })
      this.listLoading = false
    }
  }
}
</script>
